package com.mallcloud.mall.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.mall.api.entity.MallUserValueCardModel;
import com.mallcloud.mall.mall.api.entity.MallValueCardModel;
import com.mallcloud.mall.mall.api.entity.dto.*;
import com.mallcloud.mall.mall.service.MallUserCardInfoService;
import com.mallcloud.mall.mall.service.MallValueCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Api(tags = "app-储值卡查询")
@RestController
@AllArgsConstructor
@RequestMapping("/app/card")
public class AppValueCardController {
    private final MallValueCardService mallValueCardService;
    private final MallUserCardInfoService mallUserCardInfoService;

    @ApiOperation("查询储值卡列表")
    @GetMapping("/list")
    public R<List<MallValueCardModel>> list(MallValueCardModel entity) {
        return R.ok(mallValueCardService.list(new LambdaQueryWrapper<>(entity)));
    }

    @ApiOperation("查询会员储值卡列表")
    @GetMapping("/user/list")
    public R<List<MallUserValueCardModel>> userList(MallUserValueCardModel entity) {
        return R.ok(mallUserCardInfoService.list(new LambdaQueryWrapper<>(entity)));
    }

    @ApiOperation("购买储值卡")
    @PostMapping("/buy")
    public R<ProValueCardPurchase> buy(@RequestBody ProValueCardPurchase entity) {
		mallValueCardService.buy(entity);
		return R.ok(entity);
    }

    @ApiOperation("储值卡充值")
    @PostMapping("/recharge")
    public R<BigDecimal> recharge(@RequestBody ProValueCardRecharge entity) {
		return R.ok(mallValueCardService.recharge(entity));
    }

    @ApiOperation("储值卡绑定")
    @PostMapping("/bind")
    public R bind(@RequestBody ProValueCardBind entity) {
		mallValueCardService.bind(entity);
		return R.ok();
    }

    @ApiOperation("储值卡转赠")
    @PostMapping("/given")
    public R given(@RequestBody ProValueCardGiven entity) {
		mallValueCardService.given(entity);
		return R.ok();
    }

    @ApiOperation("储值卡转赠状态")
    @PostMapping("/givenStatus")
    public R givenStatus(@RequestBody ProValueCardGivenStatus entity) {
		mallValueCardService.givenStatus(entity);
		return R.ok();
    }
}
